from pydantic_settings import BaseSettings
from typing import List, Dict, Any
import os


class Settings(BaseSettings):
    # 应用配置
    app_name: str = "Suna Gateway Service"
    app_version: str = "1.0.0"
    debug: bool = True

    # 服务器配置
    host: str = "192.168.100.10"
    port: int = 9292
    workers: int = 4

    # 服务发现配置
    services: Dict[str, Dict[str, Any]] = {
        "suna-ai": {
            "url": "http://192.168.100.10:8000",
            "health_check": "/health",
            "timeout": 30,
            "retries": 3
        }
    }

    # 认证配置
    secret_key: str = os.getenv("SECRET_KEY", "gateway-secret-key")
    algorithm: str = "HS256"
    access_token_expire_minutes: int = 30

    # 限流配置
    rate_limit: int = 100
    rate_limit_window: int = 60

    # Redis配置
    redis_url: str = os.getenv("REDIS_URL", "redis://192.168.100.10:6379")

    # 日志配置
    log_level: str = "DEBUG"  # 改为 DEBUG 级别
    log_format: str = "console"  # 使用控制台格式

    # CORS配置
    cors_origins: List[str] = ["*"]
    cors_allow_credentials: bool = True
    cors_allow_methods: List[str] = ["*"]
    cors_allow_headers: List[str] = ["*"]

    class Config:
        env_file = ".env"
        case_sensitive = False


settings = Settings()